//
//  GatheringDetailViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/12/10.
//  Copyright © 2015年 reabam.com. All rights reserved.
//

#import "GatheringDetailViewController.h"
#import "RDVTabBarController.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "RDVTabBarController.h"
#import "UIButton+WebCache.h"
#import "GatheringDetailView.h"
@interface GatheringDetailViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate,UIScrollViewDelegate>
@end

@implementation GatheringDetailViewController
{
    GatheringDetailView*DetailView;
}

-(void)BackAction:(UIButton *)sender{
    
    
   [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{[super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavi];
    self.view.backgroundColor=[UIColor whiteColor];
    DetailView=[[GatheringDetailView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [self.view addSubview:DetailView];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:self. gid forKey:@"gid"];
    
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSLog(@"-----------%@", param);
    
    [HttpRequest requestData:@"Business/Gathering/Detail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"-----------%@", severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                if ([[severDataDict.dataDict objectForKey:@"status"]isEqualToString:@"Y"]) {
            
                   DetailView.statusLabel.text=@"交易成功!";
                    UIImageView *gou = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-50,50/2, 30, 30)];
                    gou.image=[UIImage imageNamed:@"gous"];
                    [DetailView.mainScroll addSubview:gou];
               
            }else{
                
                    DetailView.statusLabel.text=@"交易失败!";
                    UIImageView *gou = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-50,50/2, 30, 30)];
                    gou.image=[UIImage imageNamed:@"jiaoyishibai"];
                    [DetailView.mainScroll addSubview:gou];
                }
         
                
                NSString*GoldPrice=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"payAmount"]];
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                DetailView.payAmountLabel.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
                
                NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
                
                [AttributedStr addAttribute:NSFontAttributeName
                 
                                      value:[UIFont systemFontOfSize:20.0]
                 
                                      range:NSMakeRange(0, 1)];
                
                [AttributedStr addAttribute:NSForegroundColorAttributeName
                 
                                      value:backColor
                                      range:NSMakeRange(0, 1)];
                DetailView.payAmountLabel.attributedText = AttributedStr;
      
                if ([[severDataDict.dataDict objectForKey:@"payType"]isEqualToString:@"wx_pay_scan"]) {
                    DetailView.payTypeLabel.text=[NSString stringWithFormat:@"%@",  @"微信扫码支付"];
                   
                }
                if ([[severDataDict.dataDict objectForKey:@"payType"]isEqualToString:@"CashPay"]) {
                   DetailView.payTypeLabel.text=[NSString stringWithFormat:@"%@",  @"现金支付"];
                    
                }
                if ([[severDataDict.dataDict objectForKey:@"payType"]isEqualToString:@"IboxPay"]) {
                    DetailView.payTypeLabel.text=[NSString stringWithFormat:@"%@",  @"盒子支付"];
      
                }
                if ([[severDataDict.dataDict objectForKey:@"payType"]isEqualToString:@"AliQrPay"]) {
                    DetailView.payTypeLabel.text=[NSString stringWithFormat:@"%@",  @"支付宝支付"];
                    
                }
           
             
              
                if ([[severDataDict.dataDict objectForKey:@"orderType"]isEqualToString:@"order"]) {
                   DetailView.typeLabel.text =[NSString stringWithFormat:@"%@",@"订单"];
                   
                    
                    
                }
                if ([[severDataDict.dataDict objectForKey:@"orderType"]isEqualToString:@"service"]) {
                   DetailView.typeLabel.text =[NSString stringWithFormat:@"%@",@"服务"];
                  
                    
                }
                
                if ([[severDataDict.dataDict objectForKey:@"orderType"]isEqualToString:@"other"]) {
                   DetailView.typeLabel.text =[NSString stringWithFormat:@"%@",@"自定义"];
                  
                    
                    
                }
                
                DetailView.orderNoLabel.text=[severDataDict.dataDict objectForKey:@"orderNo"];
                DetailView.tradeNoLabel.text=[severDataDict.dataDict objectForKey:@"tradeNo"];
                DetailView.createDateLabel.text=[severDataDict.dataDict objectForKey:@"createDate"];
                NSString *s1 =[NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"remark"]]];
                UIFont *font1 = [UIFont systemFontOfSize:contenfot];
                CGSize size1 = CGSizeMake(ScreenWidth-60, 2000);
                CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
                DetailView.remarkLabel.frame=CGRectMake(20, DetailView.remark.bottom+2, ScreenWidth-40, labelsize1.height+30);
                DetailView.remarkLabel.text=s1;
                DetailView.remarkLabel.numberOfLines=0;
                [DetailView.mainScroll setContentSize:CGSizeMake(ScreenWidth, ScreenHeight)];
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];

    
    
    
    
    
    
    
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)setNavi{
    [[self rdv_tabBarController] setTabBarHidden:YES];
    
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    
    self.title=@"交易详情";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
